package net.lab1024.sa.admin.module.users.approval.controller;

import com.alibaba.excel.EasyExcel;
import net.lab1024.sa.admin.module.users.approval.dao.ConsumablesPurchaseApprovalDao;
import net.lab1024.sa.admin.module.users.approval.domain.entity.ConsumablesPurchaseApprovalEntity;
import net.lab1024.sa.admin.module.users.approval.domain.form.ConsumablePurchaseApprovalFrom;
import net.lab1024.sa.admin.module.users.approval.domain.form.ConsumablesPurchaseApprovalAddForm;
import net.lab1024.sa.admin.module.users.approval.domain.form.ConsumablesPurchaseApprovalQueryForm;
import net.lab1024.sa.admin.module.users.approval.domain.form.ConsumablesPurchaseApprovalUpdateForm;
import net.lab1024.sa.admin.module.users.approval.domain.vo.ConsumablesPurchaseApprovalVO;
import net.lab1024.sa.admin.module.users.approval.listener.approvalExcelListener;
import net.lab1024.sa.admin.module.users.approval.service.ConsumablesPurchaseApprovalService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

/**
 * 实训室耗材审批管理 Controller
 *
 * @Author 王俊权
 * @Date 2024-11-06 10:32:23
 * @Copyright 🐂🐎bloc
 */

@RestController
@Tag(name = "实训室耗材审批管理")
public class ConsumablesPurchaseApprovalController {

    @Resource
    private ConsumablesPurchaseApprovalService consumablesPurchaseApprovalService;
    @Resource
    private ConsumablesPurchaseApprovalDao consumablesPurchaseApprovalDao;

    @Operation(summary = "分页查询 @author 王俊权")
    @PostMapping("/consumablesPurchaseApproval/queryPage")
    @SaCheckPermission("consumablesPurchaseApproval:query")
    public ResponseDTO<PageResult<ConsumablesPurchaseApprovalVO>> queryPage(@RequestBody @Valid ConsumablesPurchaseApprovalQueryForm queryForm) {
        return ResponseDTO.ok(consumablesPurchaseApprovalService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author 王俊权")
    @PostMapping("/consumablesPurchaseApproval/add")
    @SaCheckPermission("consumablesPurchaseApproval:add")
    public ResponseDTO<String> add(@RequestBody @Valid ConsumablesPurchaseApprovalAddForm addForm) {
        return consumablesPurchaseApprovalService.add(addForm);
    }

    @Operation(summary = "更新 @author 王俊权")
    @PostMapping("/consumablesPurchaseApproval/update")
    @SaCheckPermission("consumablesPurchaseApproval:update")
    public ResponseDTO<String> update(@RequestBody @Valid ConsumablesPurchaseApprovalUpdateForm updateForm) {
        return consumablesPurchaseApprovalService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author 王俊权")
    @PostMapping("/consumablesPurchaseApproval/batchDelete")
    @SaCheckPermission("consumablesPurchaseApproval:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Integer> idList) {
        return consumablesPurchaseApprovalService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author 王俊权")
    @GetMapping("/consumablesPurchaseApproval/delete/{id}")
    @SaCheckPermission("consumablesPurchaseApproval:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Integer id) {
        return consumablesPurchaseApprovalService.delete(id);
    }

    @Operation(summary = "审批 @author lyy")
    @PostMapping("/consumablesPurchaseApproval/approval")
    @SaCheckPermission("consumablesPurchaseApproval:approval")
    public ResponseDTO<String> approval(@RequestBody @Valid ConsumablePurchaseApprovalFrom updateForm) {
        return consumablesPurchaseApprovalService.approvalPurchase(updateForm);
    }

    @Operation(summary = "批量入库 @author lyy")
    @PostMapping("/consumablesPurchaseApproval/uploadExcel")
    @SaCheckPermission("consumablesPurchaseApproval:batchAdd")
    public ResponseDTO<String> upload(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), ConsumablesPurchaseApprovalEntity.class,new approvalExcelListener(consumablesPurchaseApprovalService)).sheet(2).headRowNumber(2).doRead();
        return ResponseDTO.ok();
    }
}
